#pragma once

#include "BasicCamera.h"
#include "BasicMath.h"
#include "List.h"

#include "ShapeLibrary.h"
#include "TextureLibrary.h"
#include "ShaderPairLibrary.h"
#include "ModelLibrary.h"


// A node within a scene graph.
class SceneNode
{
public:
	SceneNode();

	float4x4 localTrandormation;
	float4x4 worldTransformation;

	

	void ResolveChildrenWorldTransform();
	// Adds a new node as a child to tnis node.

	void Add(SceneNode* node);

	// Removes an existing child node.
	void Remove(SceneNode* node);

	// Gets the nth child Scene node
	SceneNode* GetChild(int n);

	// Returns the number of child nodes
	int Count();

	virtual void Render(
		ID3D11DeviceContext1* Direct3DContext, 
		ModelViewProjectionConstantBuffer ModelViewProjectionBuffer,
		ID3D11Buffer* constantBuffer,
		ID3D11SamplerState* textureSampler,

		ShapeLibrary *shapeLibrary,
		TextureLibrary* textureLibrary,
		ShaderPairLibrary* shaderPairLibrary,
		ModelLibrary* modelLibrary);

	static void RendSceneNodes(	
		ID3D11DeviceContext1* Direct3DContext, 
		ModelViewProjectionConstantBuffer ModelViewProjectionBuffer,
		ID3D11Buffer* constantBuffer,
		ID3D11SamplerState* textureSampler,

		ShapeLibrary *shapeLibrary,
		TextureLibrary* textureLibrary,
		ShaderPairLibrary* shaderPairLibrary,
		ModelLibrary* modelLibrary,

		List* listOfRenderableNodes);


	virtual bool IsRenderable()
	{
		 return false;
	}

	// resolves the model tansformation of the scenegraph nodes children.
	virtual void ResolveModelTransformation(BasicCamera* camera, List* listOfRenderableNodes);

	// test if given the current model transform of the node's geometry, if
	// it intersects the view frustum of the camera then the geometry is visible.
	virtual bool IsVisibleFromCamera(BasicCamera *camera);

private:
	List *children;

	

};